<template>
  <div >
      登录页
      返回验证
    <!--  底部  -->

  </div>
</template>

<script>
import { checkTicket,reCheckTicket } from "@/api/cas";
import Cookies from "js-cookie";
import { encrypt, decrypt } from '@/utils/jsencrypt'
import { listDept, getDept, delDept, addDept, updateDept, listDeptExcludeChild } from "@/api/system/dept";

export default {
  name: "Login",
  created() {
    let r = this.GetRequest();
    console.log(r.ticket)

    this.getList(r.ticket)


    //1。验证tikect  2 获取token 3,保存TOKEN和用户信息，跳转到成功页面


  },
  methods: {
    /** 查询部门列表 */
    getList2() {
      this.loading = true;
      listDept(this.queryParams).then(response => {
        this.deptList = this.handleTree(response.data, "deptId");
        this.loading = false;
      });
    },
    GetRequest() {
      let url = location.search
      //获取url中"?"符后的字串
      let theRequest = new Object()
      if (url.indexOf('?') != -1) {
        let str = url.substr(1)
        let strs = str.split('&')
        for (let i = 0; i < strs.length; i++) {
          theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
        }
      }

      return theRequest
    },
    getList(ticket) {
      this.loading = true;
      checkTicket(ticket).then(response => {
        console.log(response,'checkTicket response')
        console.log(response.data,'checkTicket response.data')

        this.loading = false;
      });

      reCheckTicket().then(response => {
        console.log(response.code,response.token,'reCheckTicket response')
        console.log(response,'reCheckTicket response')
        
        let userInfo = {token:response.token}
        this.$store.dispatch("doLogin", userInfo).then(() => {
          this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
        }).catch(() => {
          this.loading = false;
        });

      });
    }


  }
};
</script>
